package com.shengyijie.adapter.viewadapter;

import java.util.List;
 
import com.shengyijie.activity.R;
import com.shengyijie.adapter.viewcache.CategoryListViewCache; 
import com.shengyijie.context.ContextApplication;
import com.shengyijie.model.object.baseobject.Category;
import com.shengyijie.util.Utility;


import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter; 
import android.widget.ImageView;
import android.widget.ListView; 
import android.widget.TextView;


public class CategoryListAdapter extends ArrayAdapter<Category>{
 
	private Activity activity;
	
	public CategoryListAdapter(Activity activity, List<Category> newsList,ListView listView) {
		  super(activity, 0, newsList);
		  this.activity=activity;  
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		CategoryListViewCache viewCache;
		try{ 
				if (convertView == null) {
					LayoutInflater inflater = ((Activity) this.getContext()).getLayoutInflater(); 
					convertView = inflater.inflate(R.layout.categorylist, null);  
					viewCache = new CategoryListViewCache(convertView);
					convertView.setTag(viewCache);
				}else{
					viewCache = (CategoryListViewCache) convertView.getTag(); 
				}  
				try{ 
					ImageView imageView = viewCache.getImage();  
					int resID=Utility.getRes(activity, this.getItem(position).getImageUrl());
					imageView.setBackgroundResource(resID);
  
					TextView name = viewCache.getName();   
					name.setText(getItem(position).getName());
					
				}catch(Exception e){}
		}catch(Exception e){}
		return convertView;
	}
}
